package com.zhongyu.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhongyu.service.KuaiDiCanService;
import com.zhongyu.vo.KuaiDiRespData;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.IOException;
@Service
public class KuaiDiCanServiceImpl implements KuaiDiCanService {
    private final String URI_PREFIX="https://api.apishop.net/common/express/getExpressInfo?";
@Resource
   private RestTemplate restTemplate;
    @Override
    public KuaiDiRespData getByApiKey(String apiKey,String expressNumber) {
        System.out.println("调用远程接口!");
        String uri=this.URI_PREFIX+"apiKey="+apiKey+"&expressNumber="+expressNumber;
       ResponseEntity<String> responseEntity=restTemplate.getForEntity(uri,String.class);
      String jsonStr= responseEntity.getBody();
        System.out.println("json字符串"+jsonStr);
        ObjectMapper objectMapper=new ObjectMapper();
        KuaiDiRespData respData=null;
        try {
           respData=objectMapper.readValue(jsonStr,KuaiDiRespData.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

  /*  @Override
    public KuaiDiRespData getByExpressNumber(String expressNumber) {
        return null;
    }*/
}
